<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>点击列表后高亮显示</title>
    <style>
        .active {
            color: white;
            background-color: blue;
        }
    </style>
</head>
<body>
<div id="app">
    <ul>
        <li v-for="(item, index) in items" v-on:click="itemClicked(index)" v-bind:key="index"
            v-bind:class="{active: currentIndex === index}">{{ item }}
        </li>
    </ul>
</div>
<script type="module">
    import {createApp, ref, reactive} from "../../../../../js/vue.esm-browser.js";

    const app = createApp({
        setup() {
            let items = reactive(["霸王别姬", "夜半歌声", "为你钟情", "无间道"])
            let currentIndex = ref(null)

            function itemClicked(index) {
                console.log("点击了列表项:" + index);
                console.log("点击项的内容是:" + this.items[index]);
                this.currentIndex = index
            }

            return {items, currentIndex, itemClicked}
        }
    })

    app.mount("#app")
</script>
</body>
</html>